#include "mouse.h"

/*
 * GLFW_MOUSE_BUTTON_LEFT
 * GLFW_MOUSE_BUTTON_RIGHT
 * GLFW_MOUSE_BUTTON_MIDDLE
 * 
 * GLFW_PRESS or GLFW_RELEASE
 */


MouseHandler::MouseHandler(void)
{
	
}

MouseHandler::~MouseHandler(void)
{
	
}

void MouseHandler::stateChanged(void)
{
	switch (gameState->getState())
	{
		case STATE_EDITOR: glfwSetMouseButtonCallback(&editorHandler); break;
		case STATE_GAME: glfwSetMouseButtonCallback(&gameHandler); break;
	}
}

void GLFWCALL editorHandler(int button, int action)
{
	if (!gameState->isConsoleDown())
		editor->handleClick(button, action);
}

void GLFWCALL gameHandler(int button, int action)
{
	/* spara un proiettile dell'arma corrente */
	if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
	{
		int x, y;
		glfwGetMousePos(&x, &y);
		//TODO: fargli sparare proiettile
		gamePlay->localProjectileShooted(aPlayer, Utils::toOglWidth(x) + gfxEngine->m_viewportX, Utils::toOglHeight(y) + gfxEngine->m_viewportY);
	}
}
